﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BookStore
{
    class Storage
    {
        public static string again = "y";
        public static List<Storage> obj_list = new List<Storage>();

        public static void AddObj(int choise)
        {
            StoreObject literature = new StoreObject();
            switch (choise)
            {
                case (0): literature = new Book();
                    Console.WriteLine("Название:");
                    literature.name = Console.ReadLine();
                    Console.WriteLine("Автор:");
                    (literature as Book).author = Console.ReadLine();
                    Console.WriteLine("Ввести иной возрастной ценз?(y/n)");
                    again = Console.ReadLine();
                    if (again == "y") // todo а если и не y и не n 
                    {
                        int temp;
                        while (!Int32.TryParse(Console.ReadLine(), out temp))
                        { } //TODO : общение с пользователем ? 

                        (literature as Book).censored = temp;
                    }
                    break;
                case 1: literature = new Magazine();
                    Console.WriteLine("Дата выхода (введите в формате гггг-мм-дд):");
                    (literature as Magazine).dateOut = Console.ReadLine();
                    Console.WriteLine("Ввести иной возрастной ценз?(y/n)");
                    again = Console.ReadLine();
                    if (again == "y")
                    {
                        int temp;
                        while (!Int32.TryParse(Console.ReadLine(), out temp))
                        { } //TODO : общение с пользователем ? 
                        (literature as Magazine).censored = temp;
                    }
                    Console.WriteLine("Бонус будет?(y/n)");
                    again = Console.ReadLine();
                    if (again == "y")
                        (literature as Magazine).bonus = true;
                    break;
                case 2: literature = new NewsPaper();
                    Console.WriteLine("Дата выхода (введите в формате гггг-мм-дд):");
                    (literature as NewsPaper).dateOut = Console.ReadLine();
                    break;
                case 3: literature = new Buklet();
                    Console.WriteLine("Автор:");
                    (literature as Buklet).author = Console.ReadLine();
                    break;
            }
            Console.WriteLine("Цена:");
            int temp2;
            Int32.TryParse(Console.ReadLine(), out temp2);
            literature.price = temp2;
            Console.WriteLine("Кол-во страниц:");
            literature.num_of_pages = Console.ReadLine();
            Console.WriteLine("Брэнд:");
            literature.brand = Console.ReadLine();

            obj_list.Add(literature);
        }

        public static void PrintObj(int choise)
        {
            obj_list.Sort(delegate(StoreObject a, StoreObject b)
            {
                return a.price.CompareTo(b.price);
            });

            foreach (StoreObject lit in obj_list)
            {
                switch (choise)
                {
                    case (0): if (lit is Book)
                            Console.WriteLine(lit.ToString());
                        break;
                    case (3): if (lit is Buklet)
                            Console.WriteLine(lit.ToString());
                        break;
                    case (2): if (lit is NewsPaper)
                            Console.WriteLine(lit.ToString());
                        break;
                    case (1): if (lit is Magazine)
                            Console.WriteLine(lit.ToString());
                        break;
                    case (4):
                        Console.WriteLine(lit.GetType());
                        Console.WriteLine("\n" + lit.ToString());
                        Console.WriteLine("-------------------");
                        break;

                }

            }
        }
    }
}
